import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.DefaultComboBoxModel;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import com.ha.facecamera.configserver.pojo.Gateopening;

import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GateopenDialog {

	private JDialog frame;
	private JTextField textField;
	private Gateopening gateopening;
	private JComboBox comboBox = new JComboBox();
	JComboBox comboBox_1 = new JComboBox();
	JComboBox comboBox_2 = new JComboBox();
	JTextArea textArea = new JTextArea();
	JComboBox comboBox_3 = new JComboBox();
    
	

	public JDialog getFrame() {
		return frame;
	}

	public void setFrame(JDialog frame) {
		this.frame = frame;
	}

	public Gateopening getGateopening() {
		return gateopening;
	}

	public void setGateopening(Gateopening gateopening) {
		this.gateopening = gateopening;
	}

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GateopenDialog window = new GateopenDialog();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public GateopenDialog() {
		initialize();
	}
	
	public void ma(Gateopening gateopening) {
		comboBox.setSelectedItem(gateopening.getPort());
		comboBox_1.setSelectedItem(gateopening.getDirection());
		comboBox_2.setSelectedItem(gateopening.getControltype());
		comboBox_3.setSelectedItem(gateopening.getControlpattern());
		textArea.setText(gateopening.getControlid()+"");
		textField.setText(gateopening.getEmpid());
		
		
	}
	
	public void ma1() {
		gateopening=new Gateopening();
		System.out.println(comboBox.getSelectedItem().toString()+"asfd");
		gateopening.setPort(Byte.parseByte(comboBox.getSelectedItem().toString()));
		gateopening.setDirection(Byte.parseByte(comboBox_1.getSelectedItem().toString()));
		gateopening.setControltype(Byte.parseByte(comboBox_2.getSelectedItem().toString()));
		gateopening.setControlpattern(Byte.parseByte(comboBox_3.getSelectedItem().toString()));
		gateopening.setControlid(Integer.parseInt(textArea.getText()));
		gateopening.setEmpid(textField.getText());
		
		
	}
	

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JDialog();
		frame.setBounds(100, 100, 470, 438);
		
		frame.getContentPane().setLayout(new GridLayout(0, 1, 0, 0));
		frame.setLocationRelativeTo(null); 
		frame.setModal(true);
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("端口号");
		lblNewLabel.setBounds(92, 33, 66, 24);
		panel.add(lblNewLabel);
		
		
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2"}));
		comboBox.setBounds(224, 33, 66, 24);
		comboBox.setSelectedIndex(1);
		panel.add(comboBox);
		
		JLabel lblNewLabel_1 = new JLabel("端口方向");
		lblNewLabel_1.setBounds(92, 110, 54, 24);
		panel.add(lblNewLabel_1);
		
		
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"1", "2"}));
		comboBox_1.setBounds(224, 112, 66, 22);
		comboBox_1.setSelectedIndex(1);
		panel.add(comboBox_1);
		
		JLabel lblNewLabel_2 = new JLabel("控制类型");
		lblNewLabel_2.setBounds(92, 174, 54, 15);
		panel.add(lblNewLabel_2);
		
		
		comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"1", "0"}));
		comboBox_2.setBounds(224, 171, 66, 21);
		panel.add(comboBox_2);
		
		JLabel lblNewLabel_3 = new JLabel("门禁号");
		lblNewLabel_3.setBounds(92, 266, 54, 15);
		panel.add(lblNewLabel_3);
		textArea.setText("11");
		
		
		textArea.setBounds(224, 262, 66, 24);
		panel.add(textArea);
		
		JLabel lblNewLabel_4 = new JLabel("人员id");
		lblNewLabel_4.setBounds(92, 310, 54, 15);
		panel.add(lblNewLabel_4);
		
		textField = new JTextField();
		textField.setText("0");
		textField.setBounds(224, 307, 66, 21);
		panel.add(textField);
		textField.setColumns(10);
		
		JButton btnNewButton = new JButton("设置");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ma1();
				frame.setVisible(false);
			}
		});
		btnNewButton.setBounds(167, 366, 93, 23);
		panel.add(btnNewButton);
		
		JLabel lblNewLabel_5 = new JLabel("控制模式");
		lblNewLabel_5.setBounds(92, 223, 54, 15);
		panel.add(lblNewLabel_5);
		
		
		comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2"}));
		comboBox_3.setBounds(224, 220, 66, 21);
		comboBox_3.setSelectedIndex(1);
		panel.add(comboBox_3);
	}
}
